package com.atlocal.fun;

import com.atlocal.utils.StringUtils;
import org.apache.flink.api.common.functions.FilterFunction;

/**
 * @ClassName FilterJsonFunction
 * @Description TODO 判读一个字符串是否是标准的json格式
 * @Author kongjiangjiang
 * @Date 2022/4/15 9:48
 * @Version 1.0
 **/
@SuppressWarnings("all")
public class FilterJsonFunction implements FilterFunction<String> {

    @Override
    public boolean filter(String s) throws Exception {
        //去掉字符串的前后空格
        String trimStr = s.trim();
        //判断字符串前后是否是{  }结尾
        char firstChar = trimStr.charAt(0);
        String firstString = String.valueOf(firstChar);
        char lastChar = trimStr.charAt(trimStr.length() - 1);
        String lastString = String.valueOf(lastChar);

        boolean isJson = StringUtils.isJson(s);
        return firstString.equals("{") && lastString.equals("}") && isJson;
    }
}
